package com.lottery.service;

import com.lottery.model.Combination;
import com.lottery.model.Match;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: lujianwu
 * @Date: 2025/9/2 17:42
 * @version: 1.0.0
 */
// 2. 生成组合时完整保存数据
@Service
public class CombinationService {
    // 生成C(n,9)组合（从n场中选9场）
    public List<List<Match>> generate9FromN(List<Match> selectedMatches) {
        List<List<Match>> result = new ArrayList<>();
        combine(selectedMatches, 0, new ArrayList<>(), 9, result);
        return result;
    }

    // 递归生成组合
    private void combine(List<Match> source, int start, List<Match> current, int k, List<List<Match>> result) {
        if (current.size() == k) {
            result.add(new ArrayList<>(current));
            return;
        }
        for (int i = start; i < source.size(); i++) {
            current.add(source.get(i));
            combine(source, i + 1, current, k, result);
            current.remove(current.size() - 1);
        }
    }
}